package OldCode;
/*
 * Created on Nov 4, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
 
import java.awt.geom.*;
import java.awt.*;
//import java.awt.*;
import javax.swing.*;
import java.util.*;


/**
 * This class will contain the necessary information for a 
 * SunburstMenu, it will have an arc, and a flag for if it's crossed
 * text info, and icon info, etc.
 * @author shen
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class SunburstMenuItem implements I_MenuBase {
	
	private Arc2D moArc;
	private String msName;
	private String msText;
	
	private ImageIcon moIcon;
	
	private boolean mbCrossed;
	
	private boolean mbEnabled;
	
	private boolean mbHighlight;
	
	private boolean mbVisible;
	
	private ArrayList moChildren;
	
	private SunburstMenuItem moParent;
	
	//this variable will be used to restore the angle extent of the original arc
	//because we will expand the arc sometimes, so it's important we remember the 
	//original one in order to restore the original state.  
	private double mdAngleExtent;
	
	private double mdAngleStart;
	
	//The inner and outer points are where we can connect 
	//the label with other labels. 
	private Point2D moInnerPoint;
	
	private Point2D moOuterPoint;
	
	private Point2D moStringPoint; 
	
	//I need to be able to set the background color of this component
	private Color moBackgroundColor;
	
	//This will be the relative position for this menuItem to it's parent or root
	private int miPosition;
	
	//alpha value for each item 0.0 is totally transparent
	//1.0 is totally not transparent
	private float mfAlphaValue;
	
	//this keep track of how many times
	//this node has been visited
	private int miVisitCount = 0;
	
	public SunburstMenuItem(Arc2D arc){
		
		moArc = arc;
		moChildren = new ArrayList();
		mdAngleExtent = arc.getAngleExtent();
		mdAngleStart = arc.getAngleStart();
		
	}
	
	
	public SunburstMenuItem(String str){
		msText = str;
		moChildren = new ArrayList();
	}
	
	public SunburstMenuItem add(String str){
		SunburstMenuItem item = new SunburstMenuItem(str);
		addChild(item);
		return item;
	}
	
	public void increaseVisitCount(){
		miVisitCount++;
	}
	
	public void resetVisitCount(){
		miVisitCount = 0;
	}
	
	public int getVisitCount(){
		return miVisitCount;
	}
	
	public void setVisitCount(int value){
		miVisitCount = value;
	}
	
	
	
	public void addChild(SunburstMenuItem item){
		moChildren.add(item);
		item.setParent(this);
	}
	
	public SunburstMenuItem getChildAt(int i){
		if(i >=0 && i < moChildren.size()){
			return (SunburstMenuItem) moChildren.get(i);
		}
		else{
			return null;
		}
	}
	
	public void setParent(SunburstMenuItem parent){
		moParent = parent;
	}
	
	public SunburstMenuItem getParent(){
		return moParent;
	}
	
	/**
	 * get root item for this item
	 * @return
	 */
	public SunburstMenuItem getRoot(){
		if(moParent == null) return this;
		else{
			return moParent.getRoot();
		}
	}
	
	public int getChildCount(){
		return moChildren.size();
	}
	
	/**
	 * get the top level item of this tree
	 * @return
	 */
	public SunburstMenuItem getTopItem(){
		if(getParent() == null) return this;
		else{
			return getParent().getTopItem();
		}
	}
	
	public boolean hasChildren(){
		if(moChildren.size() == 0)return false;
		else return true;
	}
	
	public SunburstMenuItem[] getAllChildren(){
		ArrayList list = new ArrayList();
		_getAllChildren(list);
		Object[] menus = list.toArray();
		SunburstMenuItem[] items = new SunburstMenuItem[menus.length];
		for(int i=0; i< menus.length; i++){
			items[i] = (SunburstMenuItem) menus[i]; 
		}
		return items;
	}
	
	private void _getAllChildren(ArrayList list){
		int size = moChildren.size();
		for(int i =0; i<size; i++){
				SunburstMenuItem item = (SunburstMenuItem) moChildren.get(i); 
				list.add(item);
				item._getAllChildren(list);
		}
	}
	
	/**
	 * This method will return nodes by level
	 * @return
	 */
	public ArrayList getAllChildrenByLevel(){
			ArrayList list = new ArrayList();
			_getAllChildrenByLevel(list);
			return list;
		}
	
	
		private void _getAllChildrenByLevel(ArrayList list){
			int size = moChildren.size();
			ArrayList aLevel = new ArrayList();
			for(int i =0; i<size; i++){
					SunburstMenuItem item = (SunburstMenuItem) moChildren.get(i); 
					aLevel.add(item);
					item._getAllChildrenByLevel(list);
			}
			if(aLevel.size() != 0)
				list.add(aLevel);
		}
	
	/**
	 * @return
	 */
	public boolean isCrossed() {
		return mbCrossed;
	}

	/**
	 * @return
	 */
	public Arc2D getArc() {
		return moArc;
	}

	/**
	 * @return
	 */
	public ImageIcon getIcon() {
		return moIcon;
	}

	/**
	 * @return
	 */
	public String getText() {
		return msText;
	}

	/**
	 * @param b
	 */
	public void setCrossed(boolean b) {
		mbCrossed = b;
	}

	/**
	 * @param arc2D
	 */
	public void setArc(Arc2D arc2D) {
		moArc = arc2D;
	}

	/**
	 * @param icon
	 */
	public void setIcon(ImageIcon icon) {
		moIcon = icon;
	}

	/**
	 * @param string
	 */
	public void setText(String string) {
		msText = string;
	}

	/**
	 * @return
	 */
	public boolean isEnabled() {
		return mbEnabled;
	}

	/**
	 * @param b
	 */
	public void setEnabled(boolean b) {
		mbEnabled = b;
	}

	/**
	 * @return
	 */
	public boolean isHighlight() {
		return mbHighlight;
	}

	/**
	 * @param b
	 */
	public void setHighlight(boolean b) {
		mbHighlight = b;
	}

	/**
	 * @return
	 */
	public double getAngleExtent() {
		return mdAngleExtent;
	}

	/**
	 * @param d
	 */
	public void setAngleExtent(double d) {
		mdAngleExtent = d;
	}

	/**
	 * @return
	 */
	public double getAngleStart() {
		return mdAngleStart;
	}

	/**
	 * @param d
	 */
	public void setAngleStart(double d) {
		mdAngleStart = d;
	}

	/**
	 * @return
	 */
	public String getName() {
		return msName;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		msName = string;
	}

	/**
	 * @return
	 */
	public Point2D getInnerPoint() {
		return moInnerPoint;
	}

	/**
	 * @return
	 */
	public Point2D getOuterPoint() {
		return moOuterPoint;
	}

	/**
	 * @param point2D
	 */
	public void setInnerPoint(Point2D point2D) {
		moInnerPoint = point2D;
	}

	/**
	 * @param point2D
	 */
	public void setOuterPoint(Point2D point2D) {
		moOuterPoint = point2D;
	}

	/**
	 * @return
	 */
	public Color getBackgroundColor() {
		return moBackgroundColor;
	}

	/**
	 * @param color
	 */
	public void setBackgroundColor(Color color) {
		moBackgroundColor = color;
	}

	/**
	 * @return
	 */
	public Point2D getStringPoint() {
		return moStringPoint;
	}

	/**
	 * @param point2D
	 */
	public void setStringPoint(Point2D point2D) {
		moStringPoint = point2D;
	}

	/**
	 * @return
	 */
	public int getPosition() {
		return miPosition;
	}

	/**
	 * @param i
	 */
	public void setPosition(int i) {
		miPosition = i;
	}
	
	public void setVisible(boolean v){
		mbVisible = v;
	}
	
	public boolean isVisible(){
		return mbVisible;
	}

	/**
	 * @return
	 */
	public float getAlphaValue() {
		return mfAlphaValue;
	}

	/**
	 * @param f
	 */
	public void setAlphaValue(float f) {
		mfAlphaValue = f;
	}

}
